//
//  MainTabBarController.m
//  YunDongGym
//
//  Created by lqq on 2018/4/16.
//  Copyright © 2018年 lqq. All rights reserved.
//

#import "MainTabBarController.h"
#import "BaseNavgationController.h"
#import "HomeRootViewController.h"
#import "GymRootViewController.h"
#import "ServiceRootViewController.h"

//test
@interface MainTabBarController ()

@end

@implementation MainTabBarController
+ (void)initialize
{
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#4A4A4A"],NSFontAttributeName:MediumFont(12)}
                                             forState:UIControlStateNormal];//设置tabbar未选中颜色
    
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#3AA7FF"],NSFontAttributeName:MediumFont(12)}
                                             forState:UIControlStateSelected];//设置tabbar选中颜色
    
    [[UITabBar appearance] setTranslucent:NO];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self configTabBarControllers];
    
    
    self.tabBar.backgroundColor = [UIColor whiteColor];
    
    self.modalTransitionStyle = UIModalTransitionStylePartialCurl;
    
    [self.tabBar setShadowImage:[UIImage imageNamed:@"bg_home_tab_cut_shadow"]];
    
    UIImage *bgImage = [UIImage imageWithColor:[UIColor whiteColor] size:CGSizeMake(kDeviceWidth, 49)];
    
    [self.tabBar setBackgroundImage:[bgImage resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10) resizingMode:UIImageResizingModeStretch]];
}


- (void)configTabBarControllers
{
    
    //首页
    HomeRootViewController *homeRootVC = [HomeRootViewController controller];
    BaseNavgationController *homeRootNav = [[BaseNavgationController alloc] initWithRootViewController:homeRootVC];
    
    //团队
    GymRootViewController *gymRootVC = [GymRootViewController controller];
    BaseNavgationController *gymRootNav = [[BaseNavgationController alloc] initWithRootViewController:gymRootVC];

    //服务
    ServiceRootViewController *serviceRootVC = [ServiceRootViewController controller];
    BaseNavgationController *serviceRootNav = [[BaseNavgationController alloc] initWithRootViewController:serviceRootVC];
    
    self.viewControllers = @[homeRootNav,gymRootNav,serviceRootNav];
    
    
    NSArray *imageNames = @[@"ic_48_home_normal",@"ic_48_vip_normal",@"ic_48_server_normal"];
    NSArray *selectImageNames = @[@"ic_48_home_secleted",@"ic_48_vip_secleted",@"ic_48_server_secleted"];
    NSArray *titles = @[@"首页",@"门店",@"服务"];
    NSArray *tabBarItems = self.tabBar.items;
    for (int i = 0; i < tabBarItems.count; i++) {
        [self configTabBarItem:[tabBarItems safeObjectAtIndex:i] imageName:[imageNames safeObjectAtIndex:i] seleceImageName:[selectImageNames safeObjectAtIndex:i] title:[titles safeObjectAtIndex:i]];
    }

}

- (void)configTabBarItem:(UITabBarItem *)tabBarItem imageName:(NSString *)imageName seleceImageName:(NSString *)selectImageName title:(NSString *)title
{
    tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem.selectedImage = [[UIImage imageNamed:selectImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    tabBarItem.imageInsets = UIEdgeInsetsMake(4.5, 0, -4.5, 0);
//    tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -2);
//    [tabBarItem setTitleTextAttributes:@{NSFontAttributeName:MediumFont(12)} forState:UIControlStateNormal];
    tabBarItem.title = title;
}


@end
